﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientChat.aspx.cs" Inherits="Client" %>

<!DOCTYPE html> 
<html>
<head>

    <title>Client Page</title>

	<style type="text/css">body {background-color: black;width: 512px;height: 600px;}
	    #itin
	    {
            width:512px;
            height:auto;
            padding:10px;
	    }
	    #chat
	    {
            width:512px;
            height:auto;
	    }
	    .InputCenter
	    {
            width: 512px;
            height:auto;
	    }
	</style>

    <script type = "text/javascript">

        function load() {
            Timer();
        }

        function Timer() {
            // TODO : Update map and chat
            var t = setTimeout("Timer()", 10000);
            alert("TICK");
        }

    </script>

</head>
<body id="map" onload="startAjax()" >
    <form runat="server">
    <asp:TextBox ID="hiddenPosText"  value="213;456" runat="server"></asp:TextBox>
        </form>

    <script type = "text/javascript">

            function startAjax() {
                Timer();
            }

            function Timer() {
                GetCoordinates();
                var t = setTimeout("Timer()", 5000);
            }

            function GetCoordinates() {
                var req = submitForm();
                    req.open("POST", "Client.aspx?ajaxtruckid=" + truckID, true);
                    req.send(true);
            }

            function submitForm() {
                var req;
                // Prepare for usual Ajax presetting
                try {
                    req = new ActiveXObject('Msxml2.XMLHTTP');
                    alert(req);
                }
                catch (e) {
                    try {
                        req = new ActiveXObject('Microsoft.XMLHTTP');
                        alert(req);
                    }
                    catch (e2) {
                        try {
                            req = new XMLHttpRequest();
                        }
                        catch (e3) {
                            req = false;
                            alert(req);
                        }
                    }
                }
                req.onreadystatechange = function () {
                    if (req.readyState == 4) {
                        if (req.status == 200) {
                            // Have receive server response
                            // Fetch it and display it on map.
                            var longitude = req.responseText.split(";")[0];
                            var latitude = req.responseText.split(";")[1];
                            myLatLng = new google.maps.LatLng(latitude, longitude);
                            marker = new google.maps.Marker({
                                position: myLatLng,
                                map: map,
                                icon: image
                            })
                        }
                    }
                }
                return req;
            }

            function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);
                return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }
    </script>

    <div id="itin">



    </div>

    <div id="chat">

        <textarea id="txtChatBox" class="InputCenter" spellcheck="false" ></textarea>
        <input id="txtChatMessage" class="InputCenter" spellcheck="false" ></input>
        <input class="InputCenter" type="button" value="Envoyer" onclick="sendChatMessage()" /></input>

    </div>


</body>
</html>